home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / LIGHT / LITE / LITEFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.6 KB  |  138 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: LiteFac.cpp 1.1 1996/07/19 00:04:22 Damien Exp $ */
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //   First Light Source Example : Beams Light                         //
  6. //--------------------------------------------------------------------//
  7. //   Implementation of the Beams Light Class Factory                  //
  8. //////////////////////////////////////////////////////////////////////// 
  9.  
  10. #ifndef __LITEFAC__
  11. #include "LITEFac.h"
  12. #endif
  13.          
  14. #ifndef __COMLITE__
  15. #include "COMLITE.h"
  16. #endif
  17.  
  18. #ifndef __LITEDLL__
  19. #include "LITEDLL.h"
  20. #endif
  21.  
  22.  
  23. // ***** ClassFactory *****
  24.   
  25. BeamsLightClassFactory::BeamsLightClassFactory() {
  26.   m_cRef=0L;  // just created so no reference used
  27.   return;
  28.   }
  29.  
  30.  
  31. BeamsLightClassFactory::~BeamsLightClassFactory() {
  32.   return;
  33.   }
  34.  
  35. // IUnknown methods of BeamsLightClassFactory                                                
  36. STDMETHODIMP BeamsLightClassFactory::QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  37.   *ppv=NULL;
  38.  
  39.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  40.     *ppv=(LPVOID)this;
  41.  
  42.   if (*ppv!=NULL) {
  43.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  44.     return NOERROR;
  45.     }
  46.   else {
  47.     return ResultFromScode(E_NOINTERFACE);
  48.     }
  49.   }
  50.  
  51.  
  52. STDMETHODIMP_(ULONG) BeamsLightClassFactory::AddRef() {
  53.   return ++m_cRef;
  54.   }
  55.  
  56.  
  57. STDMETHODIMP_(ULONG) BeamsLightClassFactory::Release() {
  58.   ULONG   UnreleaseRef;
  59.  
  60.   UnreleaseRef=--m_cRef;
  61.  
  62.   if (m_cRef == 0)
  63.     delete this; // No reference left, so delete the BeamsLightClassFactory
  64.  
  65.   return UnreleaseRef;
  66.   }
  67.  
  68. /*
  69.  * BeamsLightClassFactory::CreateInstance
  70.  *
  71.  * Parameters:
  72.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  73.  *                  being used in an aggregation.
  74.  *  riid            REFIID identifying the interface the caller
  75.  *                  desires to have for the new object.
  76.  *  ppvObj          LPVOID FAR* in which to store the desired
  77.  *                  interface pointer for the new object.
  78.  *
  79.  * Return Value:
  80.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  81.  *                  if we cannot support the requested interface.
  82.  */
  83.  
  84. STDMETHODIMP BeamsLightClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  85.   BeamsLight*      pObj = NULL;
  86.   HRESULT       hr;
  87.  
  88.   *ppvObj = NULL;
  89.   hr = ResultFromScode(E_OUTOFMEMORY);
  90.  
  91.   //Verify that a controlling unknown asks for IUnknown
  92.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  93.     return ResultFromScode(E_NOINTERFACE);
  94.  
  95.   //Create the object passing function to notify on destruction.
  96.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExLightsource))
  97.     pObj = new BeamsLight;
  98.   else
  99.     return ResultFromScode(E_NOINTERFACE);
  100.  
  101.   hr=pObj->QueryInterface(IID_I3DExLightsource, ppvObj);
  102.  
  103.   //Kill the object if initial creation failed.
  104.   if (FAILED(hr))
  105.     delete pObj;
  106.   else
  107.     global_count_Obj++;
  108.  
  109.   return hr;
  110.   }
  111.  
  112.  
  113. /*
  114.  * BeamsLightClassFactory::LockServer
  115.  *
  116.  * Purpose:
  117.  *  Increments or decrements the lock count of the DLL.  If the
  118.  *  lock count goes to zero and there are no objects, the DLL
  119.  *  is allowed to unload.
  120.  *
  121.  * Parameters:
  122.  *  fLock           BOOL specifying whether to increment or
  123.  *                  decrement the lock count.
  124.  *
  125.  * Return Value:
  126.  *  HRESULT         NOERROR always.
  127.  */
  128.  
  129. STDMETHODIMP BeamsLightClassFactory::LockServer(BOOL fLock) {
  130.   if (fLock)
  131.       global_count_Lock++;
  132.   else
  133.       global_count_Lock--;
  134.  
  135.   return NOERROR;
  136.   }
  137.  
  138.